﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="jxzy_zxlx.aspx.cs" Inherits="jxzy_zxlx" %>
<%@ Import Namespace ="System.Collections" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模拟测试</title>
<!-- #include file="head.htm"-->

<script type="text/javascript">
var $checked = false; //是否已经判卷；
var $exam_answer = '';//用户答案字符串；
var $amount = 0;//总分数(计算用);
var $name = 'taomiao';
//各种题型的分值：
var $amount_1=1;var $amount_r=1;var $amount_s=1;var $amount_q=15;

function JSclick(el){
    if (navigator.appVersion.match(/\bMSIE\b/)){
        el.click();
    }else{
        var evt = document.createEvent("MouseEvents");
        evt.initEvent("click", true, true);
        el.dispatchEvent(evt);
    }
}
//单选，选择操作
function s_select(position_id,item){
	if (!$checked){
		position = document.getElementById(position_id);
		obj = position.getElementsByTagName('span');
		if (obj[item].className == 'selected'){
			obj[item].className = 'select';
			input_nodes = position.getElementsByTagName("input");
			input_nodes[0].value = '';
		}else{
			clear(position_id);
			obj[item].className = 'selected';
			input_nodes = position.getElementsByTagName("input");
			input_nodes['user_answer'].value = String.fromCharCode(65+Number(item));
		}
	}
}

//清除选择题选项
function clear(position_id){
	position = document.getElementById(position_id);
	message_nodes=position.getElementsByTagName("span");
	num=message_nodes.length;
	for (i=0;i<num;i++ )
	{
	  message_nodes[i].className="select";
	}
}

//多选，选择操作
function m_select(position_id,item){
	if (!$checked){
		position = document.getElementById(position_id);
		obj = position.getElementsByTagName('span');
		if (obj[item].className == 'selected'){
			obj[item].className = 'select';
			input_nodes = position.getElementsByTagName("input");
			select_item = String.fromCharCode(65+Number(item));
			input_nodes['user_answer'].value = input_nodes['user_answer'].value.replace(select_item,'');
		}else{
			//clear();
			obj[item].className = 'selected';
			input_nodes = position.getElementsByTagName("input");
			input_nodes['user_answer'].value = input_nodes['user_answer'].value + String.fromCharCode(65+Number(item));
		}
	}
}

//判卷
var cost;
function check_exam(){
	if($checked!=true){
	    content = document.getElementById('inner');
	    obj = content.getElementsByTagName('div');
	    for (var i=0;i<obj.length;i++){
		    check(obj[i]);
	    }
	    $checked = true;
	    var amount = document.getElementById('amount');
	    amount.innerHTML="得分:"+$amount;
	    amount.style.display = "block";
	}
}

//判断正误
function check(obj){

	position = obj;

	input_nodes = position.getElementsByTagName("input");
	//img_nodes = position.getElementsByTagName('img');
	//img_nodes[0].style.visibility = "visible";
	//单选判断正误
	if(input_nodes['category'].value == 'simple_select'){
		if(input_nodes['user_answer'].value == input_nodes['answer'].value){
			results = '1';
			//img_nodes[0].className = 'correct';
			position.style.backgroundColor='#99FF99';
			$amount = $amount + Number(input_nodes['cate_amount'].value);
		}else{
			results = '0';
			//img_nodes[0].className = 'wrong';
			position.style.backgroundColor='#FFCCCC';
			answer_nodes = position.getElementsByTagName('h1');
			answer_nodes[0].style.display = 'inline';
		}
		//comment_nodes = position.getElementsByTagName('h2');
		//if(comment_nodes.length>0){ comment_nodes[0].style.display = 'block'; }
		$exam_answer = $exam_answer + input_nodes['id'].value + "=" + input_nodes['user_answer'].value + "&";
	}
	//分析题判断正误
	if(input_nodes['category'].value == 'subjectives'){
		if(input_nodes['user_answer'].value == input_nodes['answer'].value){
			results = '1';
			//img_nodes[0].className = 'correct';
			position.style.backgroundColor='#99FF99';
			$amount = $amount + Number(input_nodes['cate_amount'].value);
		}else{
			results = '0';
			position.style.backgroundColor='#FFCCCC';
			//img_nodes[0].className = 'wrong';
		}
		answer_nodes = position.getElementsByTagName('h2');
		answer_nodes[0].style.display = 'block';
	}
	//多选判断正误
	if(input_nodes['category'].value == 'multi_select'){
		useranswer = input_nodes['user_answer'].value;
		useranswer = useranswer.split("").sort().toString().replace(/,/gi,"");
		if(useranswer == input_nodes['answer'].value){
			results = '1';
			//img_nodes[0].className = 'correct';
			position.style.backgroundColor='#99FF99';
			$amount = $amount + Number(input_nodes['cate_amount'].value);
		}else{
			results = '0';
			//img_nodes[0].className = 'wrong';
			position.style.backgroundColor='#FFCCCC';
			answer_nodes = position.getElementsByTagName('h1');
			answer_nodes[0].style.display = 'inline';
		}
		input_nodes['user_answer'].value = useranswer;
		//comment_nodes = position.getElementsByTagName('h2');
		//if(comment_nodes.length>0){ comment_nodes[0].style.display = 'block'; }
	}
	//填空判断正误
	if(input_nodes['category'].value == 'blank'){
		answer_array = new Array();
		//answer_array = [input_nodes['answer'].value];
		answer_array = input_nodes['answer'].value.split(",");
		results ='1';
		//img_nodes[0].className = 'correct';
		position.style.backgroundColor='#99FF99';
		for(i=0;i<answer_array.length;i++){
			if(input_nodes[i].value.toLowerCase().toString() != answer_array[i].toLowerCase().toString()){
				results = '0';
				//img_nodes[0].className = 'wrong';
				position.style.backgroundColor='#FFCCCC';
				answer_nodes = position.getElementsByTagName('h3');
				answer_nodes[i].style.display = 'inline';
			}else{
				$amount = $amount + Number(input_nodes['cate_amount'].value);
			}
		}
	}
	//完型填空判断正误
	if(input_nodes['category'].value == "cloze"){
			answer_array = new Array();
			results ='1';
			//img_nodes[0].className = 'correct';
			subject = position.getElementsByTagName("select");			
			answer_array = input_nodes['answer'].value.split('$');
			answer_nodes = position.getElementsByTagName('h1');
			for(i=0;i<answer_array.length;i++){
				//alert(subject[i].value);
				subject[i].style.color = 'white';
				if(subject[i].value == answer_array[i]){
					subject[i].style.backgroundColor = 'green';
				}else{
					subject[i].style.backgroundColor = 'red';
					results ='0';
					answer_nodes[i].style.display = 'inline';
					//img_nodes[0].className = 'wrong';
				}
			} 
			if(results =='1'){
				$amount = $amount + Number(input_nodes['cate_amount'].value);
				position.style.backgroundColor='#99FF99';
			}else
				position.style.backgroundColor='#FFCCCC';
	}
	//sendResults(input_nodes['id'].value,results);
	comment_nodes = position.getElementsByTagName('h2');
	if(comment_nodes.length>0){ comment_nodes[0].style.display = 'block'; }
	//提交到服务器答题结果
	}
//点击查看大图片
function lookimg(str){
//var newwin=window.open()
//newwin.document.write("<img src="+str+" />")
}

function post_answer(sid,answer){
 var xmlHttp;
 if (window.ActiveXObject) {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 }
 else if (window.XMLHttpRequest) {
  xmlHttp = new XMLHttpRequest();
 }
 xmlHttp.open("GET","/exams/save_answer//"+sid+"/"+answer,true);
 xmlHttp.send(null);
}

var CallTimeLen = "0";
var begintime;
var timer = null;

function startExam(){
	document.getElementById('loading').style.display='none';
	document.getElementById('startExam').style.display='none';
	document.getElementsByTagName('html')[0].style.overflowY = 'auto';	

    document.getElementById('conversestart').style.display = 'none';
    document.getElementById('stop').style.display = 'block';

    DoConverseCallTimer();
}

function DoConverseCallTimer()
{
  var minute="0";
  var second="0";
  begintime = parseInt(begintime)-1;
  minute = parseInt(begintime/60);
  second = begintime%60;
  if(minute=="0")
  {
   //document.frmtimer.thzt.value ="您剩余的时间为:"+second+"秒";
   document.getElementById('timeShow').innerHTML = second+"秒";
  }
  else
  {
   //document.frmtimer.thzt.value ="您剩余的时间为:"+minute+"分"+second+"秒";
   document.getElementById('timeShow').innerHTML = minute+"分"+second+"秒";
  }
  timer1 = window.setTimeout("DoConverseCallTimer()",1000);
  //window.top.frames['mainFrame'].start_exam('right');
  counttime = counttime +1;
}


function stopExam(){
    clearTimeout(window.timer1);
    cost = counttime;
    check_exam();
}

 begintime = 60*60;
 counttime = 0;
</script>
</head>
<body>
<!-- #include file="header.htm"-->
<div class="wapper">

    <div style="float:left; width:760px">
        <!-- #include file="jxzy_zxlx_main.htm"-->
    </div>
    <div style="float:left; width:197px">
        <!-- #include file="jxzy_zxlx_right.htm"-->
    </div>
</div>
</body>
</html>